package com.xsx.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;

public class ContextServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//    1.获取web.xml中配置的上下文参数context-param
        ServletContext context = getServletContext();
        String userName = context.getInitParameter("userName");
        System.out.println("userName的值是:"+userName);
        String id = context.getInitParameter("id");
        System.out.println("id:"+id);
        String contextPath = context.getContextPath();
//        2.获取当前工程路径，格式：/工程路径
        System.out.println(contextPath);
//        3.获取工程部署后再服务器硬盘上的绝对路径
        //斜杠被服务器解析地址为：http://ip:prot/工程名/
        System.out.println("工程部署的路径："+context.getRealPath("/"));


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
